<?php

namespace app\admin\controller\page;

use app\common\controller\Backend;

/**
 * 测试管理
 *
 * @icon fa fa-circle-o
 */
class Page extends Backend
{
    
    /**
     * Page模型对象
     * @var \app\admin\model\Page
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Page;
        $this->view->assign("flagList", $this->model->getFlagList());
        $this->view->assign("stateList", $this->model->getStateList());
    }

    public function import()
    {
        parent::import();
    }

    public function index()
    {
        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->with('category')
                ->where($where)
                ->order($sort, $order)
                ->count();
            $list = $this->model
                ->with('category')
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch();
    }
 
     //分类
     public function categorydate(){
         $where['type']='page';
        $list = db("category")->field('name,id')->where($where)->select();
        if ($list){
            $arr = [];
            foreach($list as $k => $v){
                $arr[$v['id']] = $v['name'];
            }
            $json = json($arr);
        }
        return $json;
    }
    

}
